package com.genghis.rapidcrm.web.view.model;

import com.genghis.rapidcrm.kernel.RapidLinkModel;
import edu.jetwinner.common.EasyStringUtil;
import org.springframework.beans.BeanUtils;

/**
 * @author xulixin
 */
public class RapidCssScriptModel extends BaseScriptModel {

    public static RapidCssScriptModel getInstanceFromLinkObject(RapidLinkModel linkModel) {
        RapidCssScriptModel scriptModel = new RapidCssScriptModel();
        BeanUtils.copyProperties(scriptModel, linkModel);
        return scriptModel;
    }

    public static final String DEFAULT_REL = "stylesheet";
    private static final String DEFAULT_MEDIA = "all";
    private static final String DEFAULT_TYPE = "text/css";

    public static final String LESS_REL = "stylesheet/less";

    private String rel;
    private String media;
    private String type;
    private String href;

    /**
     * Function to get the rel attribute value
     * @return <String>
     */
    public String getRel(){
        if(EasyStringUtil.isBlank(this.rel)){
            this.rel = DEFAULT_REL;
        }
        return this.rel;
    }

    /**
     * Function to get the media attribute value
     * @return <String>
     */
    public String getMedia(){
        if(EasyStringUtil.isBlank(this.media)){
            this.media = DEFAULT_MEDIA;
        }
        return this.media;
    }

    /**
     * Function to get the type attribute value
     * @return <String>
     */
    public String getType(){
        if(EasyStringUtil.isBlank(this.type)){
            this.type = DEFAULT_TYPE;
        }
        return this.type;
    }

    /**
     * Function to get the href attribute value
     * @return <String>
     */
    public String getHref() {
        String source = this.href;
        if(EasyStringUtil.isBlank(this.href)) {
            this.href = this.getLinkUrl();
        }
        return this.href;
    }

    public RapidCssScriptModel setRel(String rel) {
        this.rel = rel;
        return this;
    }

    public RapidCssScriptModel setMedia(String media) {
        this.media = media;
        return this;
    }

    public RapidCssScriptModel setType(String type) {
        this.type = type;
        return this;
    }

    public RapidCssScriptModel setHref(String href) {
        this.href = href;
        return this;
    }
}
